<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<style type="text/css">
.order_search {
	width: 228px;
	padding: 20px 5px;
	margin: 0px;
	padding: 0px;
	font-size: 12px;
	font-family: "Microsoft YaHei", '微软雅黑', 'Simsun', Verdana, Arial,
		Helvetica, sans-serif;
	color: #666;
}

.order_search ul {
	float: left;
	width: 228px;
}

ul {
	list-style: none;
}

.clr {
	clear: both;
	width: 0px;
	height: 0px;
	line-height: 0px;
	font-size: 0px;
}

.Search_operate {
	border-top: 1px dotted #ccc;
	text-align: right;
	line-height: 24px;
	/* padding-top: 8px; */
	/* margin-top: 30px; */
}
/* 强制一个高度，这样标签页就不会随着内容高度的改变而改变 */
.ui-tabs .ui-tabs-nav {
	clear: left;
	padding: 0 .2em .2em .2em;
}

.ui-tabs .ui-tabs-nav li {
	top: auto;
	bottom: 0;
	margin: 0 .2em 1px 0;
	border-bottom: auto;
	border-top: 0;
	border-bottom-width: 1px;
}

.ui-tabs .ui-tabs-panel {
	padding-top: 1px;
	padding-left: 10px;
	padding-bottom: 0px;
}
.ui-tabs .ui-tabs-nav .ui-tabs-anchor{
	float: left;
	padding: .1em 1em;
	text-decoration: none;
}
.ui-widget-content {
/* 	background: #00B895 !important;  */
	/* 	#58B4C3 */
	font-size: 12px;
}
ul li{
	margin-top: 5px;
}
 
</style>
</head>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">手动拉单 </a></li>
		</ul>
		<div id="tabs-1">
			<div class="order_find_cls">
				<table class="layout_tab" >
					<tr>
						<td valign="top">
							<div class="order_search ui-widget-content">
								<ul>
									<li>
										<div class="title">店铺名称：</div>
										<div class="event">
											<input  id="cs_name" type="text"  value="" 
												style="width:120px">
										</div>
										<div class="clr"></div>
									</li>
									<li>
										<div class="title">平台归属：</div>
										<div class="event">
											<select id="platform_code" class="input_text2 input_cookie"
												style="width:120px">
												<option value="">-- 全部 --</option>
												<option value="E">Ebay</option>
												<option value="A">亚马逊</option>
												<option value="S">速卖通</option>
											</select>
										</div>
										<div class="clr"></div>
									</li>
								</ul>
								<div class="clr"></div>
								<div class="Search_operate">
									<input name="manually_btnClean" id="manually_btnClean" type="button" value="清 空"
										class="publicBtn"
										style="margin-top: 30px; margin-right: 20px; margin-bottom: 20px;">
									<input id="manually_btnQuery" name="manually_btnQuery" type="button" value="查 询"
										class="publicBtn2"
										style="margin-top: 30px; margin-right: 20px; margin-bottom: 20px;">
								</div>
							</div>
						</td>
						<td >
							
							<div style="margin-right: 10px; margin-bottom: 8px;">
							<font color="#933">&nbsp;&nbsp;温馨提示：&nbsp;&nbsp;</font>
							<font color="#933" style="margin-right: 50px;">
							1、拉取订单时间段最大支持3天&nbsp;&nbsp;
							2、每天只允许手动拉取50次订单    </font> 
							<span>
							起始时间：<input type="text"  id="pull_date_begin" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',el:$dp.$('pull_date_begin'),startDate:'{%y}-%M-{%d-31}',maxDate:'{%y}-%M-{%d}',readOnly:true})"/>
						            结束时间：<input type="text" id="pull_date_end" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',el:$dp.$('pull_date_end'),startDate:'{%y}-%M-{%d}',maxDate:'{%y}-%M-{%d}',readOnly:true})"/>
							&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="pull_order_btn" value="拉单">
							</span>
							</div>
							<div>
								<table id="manuallyShop_grid"></table>
								<div id="manuallyShop_pager"></div>
							</div>
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
	<div id="pullOrder_log_dialog" title="拉单错误信息">
	</div>
	<div id="syncOrder_log_dialog" title="同步订单错误信息">
	</div>
</body>

<script type="text/javascript">
	$(function() {
		$("#tabs").tabs({
			active : 0
		});
		 
		 $( "#effect" ).hide();
		//查询手动拉单信息
		$("#pull_order_btn").button().click(function(event) {
			var pull_date_begin=$("#pull_date_begin").val();
			var pull_date_end=$("#pull_date_end").val();
			var cs_id=$("input[name='cs_id']:checked").val();
			var plat_code=$("input[name='cs_id']:checked").attr("plat_code");
			var cm_id=$("input[name='cs_id']:checked").attr("cm_id");
			if(!cs_id){
				$.jqUiHelp.alertMsg({
					html:'请选中要手动拉单的店铺',
					title:'提示信息',
					modal:true
				})
				return;
			}
			if(pull_date_begin==''||pull_date_end==''){
				$.jqUiHelp.alertMsg({
					html:'开始时间和结束时间都不能为空',
					title:'提示信息',
					modal:true
				})
				return;
			}
			if(pull_date_begin && pull_date_end && pull_date_end < pull_date_begin){
				$.jqUiHelp.alertMsg({
					html:'开始时间不能小于结束时间，请重新设置条件!',
					title:'提示信息',
					modal:true
				});
				return;
			}
			var begintime_ms = new Date(Date.parse(pull_date_begin.replace(/-/g, "/"))); //begintime 为开始时间

			var endtime_ms = new Date(Date.parse(pull_date_end.replace(/-/g, "/")));   // endtime 为结束时间
			
			var date_time_ms = endtime_ms.getTime() - begintime_ms.getTime();  // 时间差的毫秒数

			//计算出相差天数
			var days=Math.floor(date_time_ms/(24*60*60*1000));
			if(days > 3){
				$.jqUiHelp.alertMsg({
					html:'请选择时间段不要超过3天',
					title:'提示信息',
					modal:true
				})
				return ;
			}
			
			
			var param={'cs_id':cs_id,'cm_id':cm_id,'platform_code':plat_code,'start_time':pull_date_begin,'end_time':pull_date_end};
			$.global.showMask({
				  msg:"正在拉单请稍后...",
				  width:250,
				  height:30
				});
			$.ajax({
				url:'${ctx}/manually/manuallyPullOrder',
				type:"POST",
				data:param,
				dataType: "json",
				success:function(msg){
					$.global.closeMask();
					var obj=msg['success'];
					if(msg['success']){
						var orderSuccessNum=obj['orderSuccessNum'];
						var rsCode=obj['rsCode'];
						var rsDesc=obj['rsDesc']?obj['rsDesc']:"";
						if(rsCode=='Y'){
							$.jqUiHelp.showEffect({
								title:'拉单结果',
								closetime:5000,
								html:"<font color='#008000'>&nbsp;&nbsp;&nbsp;成功拉取订单,成功单数为："+orderSuccessNum+"</font>",
								right:"4px",
								bottom:"0px"
							});
						}else if(rsCode=='N'){
							var erordiv="<font color='red'>&nbsp;&nbsp;&nbsp;"+ rsDesc+"</font>";
							$.jqUiHelp.showEffect({
								title:'拉单结果',
								closetime:5000,
								html:erordiv,
								right:"4px",
								bottom:"0px"
							});
						}
					}else if(msg['error']){
						var er=msg['error'];
						var mydiv="";
						if(er==1){
							mydiv="<font color='red'>&nbsp;&nbsp;&nbsp; 拉单次数超出!</font>";
						}else if(er==2){
							mydiv="<font color='red'>&nbsp;&nbsp;&nbsp; 请等待数分后操作!</font>";
						}else if(er==3){
							mydiv="<font color='red'>&nbsp;&nbsp;&nbsp; 该店铺不存在</font>";
						}else if(er==4){
							mydiv="<font color='red'>&nbsp;&nbsp;&nbsp; 手动拉单服务异常,请联系程序员</font>";
						}
						$.jqUiHelp.showEffect({
							title:'拉单结果',
							html:mydiv,
							closetime:5000,
							right:"4px",
							bottom:"0px"
						});
					}
				
					
				}
			});
				
			
			
		});
		
		/**
		 * 查询手动拉单店铺
		 */
		$("#manually_btnClean").button().click(function(event) {
			$("#cs_name").val("");
			$("#platform_code").val("");
		});
		$("#manually_btnQuery").button().click(function(event) {
			var cs_name=$("#cs_name").val();
			var platform_code=$("#platform_code").val();
			var param={'cs_name':cs_name
					    ,'cs_platform_code':platform_code
					   };
		$("#manuallyShop_grid").jqGrid('setGridParam',{
				postData:param
				}).trigger("reloadGrid");
		});
		
		
	
		var h = $("#main_center").height();
		var w = $("#main_center").width()-258;
		//当浏览器大小变化时
		$(window).resize(function() {
			h = $("#main_center").height();
			w = $("#main_center").width()-258;
			$(".ui-jqgrid-bdiv").css('height', h - (h *  0.281));
			$("#manuallyShop_grid").setGridWidth(w);
		});
		
		//拉单日志grid
		$("#manuallyShop_grid").jqGrid(
				{
					url : '${ctx}/manually/findManuallyShopPage.action',
					datatype : "json",
					mtype:'POST',
					colNames : [ '选择','客户ID','店铺代码','店铺名称','平台类型', '站点','店铺状态','创建时间', '授权过期时间'],
					colModel : [ 
					 {name : 'cs_id',index : 'cs_id',width : 55,align : "center",
						 formatter:function(cellvalue, options, rowObject){
							var platCode=rowObject['cs_platform_code'];
							var cm_id=rowObject['cm_id'];
						 	var val="<input type='radio' name='cs_id' value="+cellvalue+" plat_code="+platCode+" cm_id="+cm_id+">";
						 	return val;
					 }},
					 {name : 'cm_id',index:'cm_id',width:100},
					 {name : 'cs_code',index : 'cs_code',width : 100,align : "center"},
					 {name : 'cs_name',index : 'cs_name',width : 150,align : "center"},
					 {name : 'cs_platform_code',index : 'cs_platform_code',width : 150,align : "center",sortable : false},
					 {name : 'cs_site',index :'cs_site',width : 120,align : "center"}, 
					 {name : 'cs_authorize',index :'cs_authorize',width : 120,align : "center",
						 formatter:function(cellvalue, options, rowObject){
						  	if(cellvalue=='Y'){
						  		return "<font color='green' >已授权</font>"
						  	}else{
						  		 var error_msg=rowObject['error_msg'];
						  		$( "#pullOrder_log_dialog" ).html(error_msg)
						  		return "<a class='showPullOrderLogfailure'   style='cursor:pointer;'>"
						  		+"<font color='red' >未授权</font></a>"
						  	}
					 	}},
					 {name : 'cs_createdate',index : 'cs_createdate',width : 150,sortable : true
					 		,formatter:function(cellvalue, options, rowObject){
	 							 return $.global.formatDateT(cellvalue);
							 }
					 } ,
					 {name : 'cs_token_timeout',index : 'cs_token_timeout',width : 150,sortable : true
						 ,formatter:function(cellvalue, options, rowObject){
							 if(cellvalue!=null){
								 return $.global.formatDateT(cellvalue);
							 }else{
								 return "";
							 }
						 }
					 }, 
					],
					rowNum : 5,
					rowList : [ 5, 10, 15 ],
					pager : '#manuallyShop_pager',
					sortname : 'cs_createdate',
					rownumbers:true,
					rownumWidth:25,
					viewrecords : true,
					viewsortcols:[true,'vertical',true],
					width:w,
					shrinkToFit:false,
					autoScroll: true, 
					sortorder : "desc",
					height : h - (h * 0.281)
				}).navGrid('#manuallyShop_pager',{edit:false,add:false,del:false});
	});
</script>
<script type="text/javascript" src="${ctx}/js/edit_jqui_tabs.js"></script>
</html>